import java.util.Scanner;

public class MaximumSubarraySum {
    public static int find(int[] nums) {
        int maxSum = nums[0];
        int Sum = nums[0];
        
        for (int i = 1; i < nums.length; i++) {
           Sum = Math.max(nums[i], Sum + nums[i]);
            maxSum = Math.max(maxSum, Sum);
        }
        
        return maxSum;
    }

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int[] nums = new int[n];
        for (int i = 0; i < n; i++) {
         nums[n] = scanner.nextInt();
        }
        int maxSum = find(nums);
        System.out.println(maxSum);
    }
}